package com.newtouch.cq.lang.result;

import com.newtouch.cq.lang.em.BaseExceptionEnum;
import com.newtouch.cq.lang.exception.IMccExceptionInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * 有数据返回对象
 *
 * @param <T>
 * @author Alex
 */
@Getter
@Setter
@ApiModel("返回对象")
public class MccObjectResult<T> extends MccResult {

    @ApiModelProperty(value = "data",dataType = "object")
    private T data;

    public MccObjectResult( IMccExceptionInfo info) {
        super( info);
    }

    public <E> MccObjectResult<E> successMsg(String message, E data) {
        return new MccObjectResult<E>( BaseExceptionEnum.SUCCESS).message(message).data(data);
    }

    public static <E> MccObjectResult<E> success(E data) {
        return new MccObjectResult<E>( BaseExceptionEnum.SUCCESS).data(data);
    }

    private MccObjectResult message(String message) {
        this.message = message;
        return this;
    }

    private MccObjectResult<T> data(T data) {
        this.data = data;
        return this;
    }
}
